<?php
declare (strict_types = 1);
namespace app\admin\controller;

use think\Request;
use think\facade\{View, Session};

use app\common\model\{SystemAdmin, SystemMenu};

class IndexController extends BaseController
{
    public function index()
    {
        $where = ['pid' => 0, 'is_show' => 1];
        $field = ['id', 'pid', 'icon', 'concat("' . getUrl() . '/' . '", module, "/", controller, "/", action)' => 'rule', 'name'];
        
        $menu = SystemMenu::getList($where, 0, 0, 0, $field, 'sort DESC, id');

        if($menu !== false){
            foreach ($menu as $key => $value) {
                $menu[$key]['list'] = SystemMenu::getList(['pid' => $value['id'], 'is_show' => 1], 0, 0, 0, $field, 'id');
            }
        }else{
            $menu = [];
        }

        View::assign('menu', $menu);
        View::assign('admin', Session::get('token'));
        return view();
    }

    public function home()
    {
        /** 会员数量 */
        $user_count = 0;

        /** 销量 */
        $order_total = 0;

        View::assign('user_count', $user_count);
        View::assign('order_total', $order_total);
        View::assign('admin', Session::get('token'));
        return view();
    }
}
